package com.erlinyou.im.web.controller.chat;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.erlinyou.im.model.black.UserBlack;
import com.erlinyou.im.model.black.UserBlackKey;
import com.erlinyou.im.model.goodfirend.Goodfirend;
import com.erlinyou.im.model.motion.UserImage;
import com.erlinyou.im.model.motion.UserMotion;
import com.erlinyou.im.model.motion.UserMotionKey;
import com.erlinyou.im.model.motion.UserMotionLike;
import com.erlinyou.im.model.motion.UserMotionLikeKey;
import com.erlinyou.im.service.black.UserBlackService;
import com.erlinyou.im.service.goodfirend.GoodfirendService;
import com.erlinyou.im.service.motion.UserImageService;
import com.erlinyou.im.service.motion.UserMotionLikeService;
import com.erlinyou.im.service.motion.UserMotionService;
import com.erlinyou.im.web.controller.base.GetFriendStepNumVo;
import com.erlinyou.im.web.controller.base.ResultCode;
import com.erlinyou.im.web.controller.base.ResultJson;
import com.erlinyou.im.web.controller.base.ResultJsonBuild;
import com.erlinyou.im.web.controller.base.SiteUtil;
import com.erlinyou.travel.service.user.IUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RequestMapping(value = "motion")
@Controller
@Api(tags = { "Motion" })
@CrossOrigin(exposedHeaders={"xAuthToken"})
public class MotionController {

	private static Logger logger = LoggerFactory.getLogger(ChatMessageController.class);
	
	@Autowired
	private UserMotionService userMotionService;
	@Autowired
	private GoodfirendService goodfirendService;
	@Autowired
	private UserMotionLikeService userMotionLikeService;
	@Autowired
	private IUserService userService;
	@Autowired
	private UserBlackService userBlackService;
	
	@Autowired
	private UserImageService userImageService;
	
	@ApiOperation(value = "修改运动步数", notes = "修改运动步数")
	@ApiImplicitParams({ @ApiImplicitParam(name = "num", required = true, value = "步数", dataType="int",example="0", paramType = "query") })
	@PostMapping(value = "/updateUserStepNum")
	@ResponseBody
	public ResultJson<Object> updateUserStepNum(HttpServletRequest request, @RequestParam(required = true) int num) {
		Long userId = SiteUtil.getCurrUserId(request);
		long dateTime = getDateTime();
	/*	UserMotionKey userMotionKey = new UserMotionKey();
		userMotionKey.setCreateDate(dateTime);
		userMotionKey.setUserid(userId);*/
		UserMotion userMotion = userMotionService.findByUseridAndCreateDate(userId,dateTime);
		boolean zt = false;
		if(userMotion!=null) {
			userMotion.setStepNum(num);
			zt=userMotionService.save(userMotion)!=null;
		}else {
			UserMotion motion = new UserMotion();
			motion.setCreateDate(dateTime);
			motion.setUserid(userId);
			motion.setStepNum(Integer.valueOf(num));
			zt=userMotionService.save(motion)!=null;
		}
		
		
		if(zt){
			return ResultJsonBuild.buildObj(ResultCode.SUCCESS);
		}else{
			return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);	
		}
	}
/*	@ApiOperation(value = "测试修改运动步数", notes = "修改运动步数")
	@ApiImplicitParams({ @ApiImplicitParam(name = "userId", required = true, value = "用户id", dataType="int",example="0", paramType = "query"),
		@ApiImplicitParam(name = "num", required = true, value = "步数", dataType="String", paramType = "query")
	})
	@PostMapping(value = "/testupdateUserStepNum")
	@ResponseBody
	public ResultJson<Object> testupdateUserStepNum(HttpServletRequest request, @RequestParam(required = true) Long userId,@RequestParam(required = true) String num) {
	//	Long userId = SiteUtil.getCurrUserId(request);
		long dateTime = getDateTime();
		UserMotion userMotion = userMotionService.findByUseridAndCreateDate(userId,dateTime);
		boolean zt = false;
		if(userMotion!=null) {
			userMotion.setStepNum(Integer.valueOf(num));
			zt=userMotionService.save(userMotion)!=null;
		}else {
			UserMotion motion = new UserMotion();
			motion.setCreateDate(dateTime);
			motion.setUserid(userId);
			motion.setStepNum(Integer.valueOf(num));
			zt=userMotionService.save(motion)!=null;
		}
		
		
		if(zt){
			return ResultJsonBuild.buildObj(ResultCode.SUCCESS);
		}else{
			return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);	
		}
	}
	*/
	@ApiOperation(value = "获取好友运动步数", notes = "获取好友运动步数")
	@ApiImplicitParams({ @ApiImplicitParam(name = "createDate", required = true, value = "时间戳", dataType="String", paramType = "query") })
	@PostMapping(value = "/getFriendStepNum")
	@ResponseBody
	public ResultJson<List<GetFriendStepNumVo>> getFriendStepNum(HttpServletRequest request, @RequestParam(required = true) String createDate){
		Long userid = SiteUtil.getCurrUserId(request);
		ResultJson<List<GetFriendStepNumVo>> resultJson = new ResultJson<List<GetFriendStepNumVo>>();
		//
		List<Map<String, Object>> goodfirendIds = goodfirendService.findByUseridAndRelation(userid);
		
		
		StringBuffer stringBuffer = new StringBuffer();
		String ids = null;
		if(goodfirendIds!=null && goodfirendIds.size()>0){
			for (Map<String, Object> goodfirids : goodfirendIds) {
				stringBuffer.append(goodfirids.get("jid")+",");
			}
			stringBuffer.append(String.valueOf(userid));
			ids = stringBuffer.toString();
		}else {
			return resultJson.setCode(ResultCode.UNKONW_ERROR.getCode());
		}
		
		List<Map<String,Object>> friendStepNum = userMotionService.getFriendStepNum(ids, Long.valueOf(createDate));
		List<Map<String,Object>> countByUserid = userMotionLikeService.countByUserid(ids,Long.valueOf(createDate));
		List<Map<String, Object>> isLikelist = userMotionLikeService.iSLike(userid,Long.valueOf(createDate));
		List<Map<String,Object>> findByUserid = userService.selectByUserid(ids);
		
 		List<GetFriendStepNumVo> resultList = new ArrayList<GetFriendStepNumVo>();
		for (Map<String, Object> map : friendStepNum) {
			GetFriendStepNumVo getFriendStepNumVo = new GetFriendStepNumVo();
			String ruserid = map.get("userid").toString();
			int stepNum = Integer.valueOf(map.get("stepNum").toString());
			getFriendStepNumVo.setUserid(Long.valueOf(ruserid).longValue());
			getFriendStepNumVo.setStepNum(stepNum);
			getFriendStepNumVo.setCreateDate(Long.valueOf(createDate));
			getFriendStepNumVo.setIsLike(false);
			for (Map<String,Object> map1 : isLikelist) {
				if(map1.get("zuserid").toString().equals(ruserid)) {
					getFriendStepNumVo.setIsLike(true);
				}
			}
			for (Map<String, Object> map1 : countByUserid) {
				if(map1.get("zuserid").toString().equals(ruserid)) {
					getFriendStepNumVo.setCountLike(Integer.valueOf(map1.get("count").toString()));
					break;
				}
			}
			for (Map<String, Object> map2 : findByUserid) {
				if(map2.get("userid").toString().equals(ruserid)) {
					getFriendStepNumVo.setImage(map2.get("image").toString());
					getFriendStepNumVo.setNickName(map2.get("nickName").toString());
					break;
				}
			}
			resultList.add(getFriendStepNumVo);
		}
		if(resultList.size()==0){
			List<GetFriendStepNumVo> resultList1 = null;
			return resultJson.setObj(resultList1);
		}
		Collections.sort(resultList);
		return resultJson.setObj(resultList);
	}

	@ApiOperation(value = "根据好友ID获取好友运动步数", notes = "获取好友运动步数")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "createDate", required = true, value = "时间戳", dataType="String", paramType = "query") ,
			@ApiImplicitParam(name = "userid", required = true, value = "用户id", dataType="Long", paramType = "query") ,
	})
	@PostMapping(value = "/getFriendStepNumByUserId")
	@ResponseBody
	public ResultJson<List<GetFriendStepNumVo>> getFriendStepNumByUserId(HttpServletRequest request,
																		 @RequestParam String createDate,
																		 @RequestParam Long userid){
		//Long userid = SiteUtil.getCurrUserId(request);
		ResultJson<List<GetFriendStepNumVo>> resultJson = new ResultJson<List<GetFriendStepNumVo>>();
		//
		List<Map<String, Object>> goodfirendIds = goodfirendService.findByUseridAndRelation(userid);


		StringBuffer stringBuffer = new StringBuffer();
		String ids = null;
		if(goodfirendIds!=null && goodfirendIds.size()>0){
			for (Map<String, Object> goodfirids : goodfirendIds) {
				stringBuffer.append(goodfirids.get("jid")+",");
			}
			stringBuffer.append(String.valueOf(userid));
			ids = stringBuffer.toString();
		}else {
			return resultJson.setCode(ResultCode.UNKONW_ERROR.getCode());
		}

		List<Map<String,Object>> friendStepNum = userMotionService.getFriendStepNum(ids, Long.valueOf(createDate));
		List<Map<String,Object>> countByUserid = userMotionLikeService.countByUserid(ids,Long.valueOf(createDate));
		List<Map<String, Object>> isLikelist = userMotionLikeService.iSLike(userid,Long.valueOf(createDate));
		List<Map<String,Object>> findByUserid = userService.selectByUserid(ids);

		List<GetFriendStepNumVo> resultList = new ArrayList<GetFriendStepNumVo>();
		for (Map<String, Object> map : friendStepNum) {
			GetFriendStepNumVo getFriendStepNumVo = new GetFriendStepNumVo();
			String ruserid = map.get("userid").toString();
			int stepNum = Integer.valueOf(map.get("stepNum").toString());
			getFriendStepNumVo.setUserid(Long.valueOf(ruserid).longValue());
			getFriendStepNumVo.setStepNum(stepNum);
			getFriendStepNumVo.setCreateDate(Long.valueOf(createDate));
			getFriendStepNumVo.setIsLike(false);
			for (Map<String,Object> map1 : isLikelist) {
				if(map1.get("zuserid").toString().equals(ruserid)) {
					getFriendStepNumVo.setIsLike(true);
				}
			}
			for (Map<String, Object> map1 : countByUserid) {
				if(map1.get("zuserid").toString().equals(ruserid)) {
					getFriendStepNumVo.setCountLike(Integer.valueOf(map1.get("count").toString()));
					break;
				}
			}
			for (Map<String, Object> map2 : findByUserid) {
				if(map2.get("userid").toString().equals(ruserid)) {
					getFriendStepNumVo.setImage(map2.get("image").toString());
					getFriendStepNumVo.setNickName(map2.get("nickName").toString());
					break;
				}
			}
			resultList.add(getFriendStepNumVo);
		}
		if(resultList.size()==0){
			List<GetFriendStepNumVo> resultList1 = null;
			return resultJson.setObj(resultList1);
		}
		Collections.sort(resultList);
		return resultJson.setObj(resultList);
	}
	
	@ApiOperation(value = "运动点赞", notes = "运动点赞")
	@ApiImplicitParams({ @ApiImplicitParam(name = "rid", required = true, value = "对方ID", dataType="String", paramType = "query"),
		@ApiImplicitParam(name = "createDate", required = true, value = "时间戳(13位的零点数据)", dataType="String", paramType = "query") })
	@PostMapping(value = "/motionLike")
	@ResponseBody
	public ResultJson<Object> motionLike(HttpServletRequest request, @RequestParam(required = true)Long rid, @RequestParam(required = true)Long createDate) {
		Long userId = SiteUtil.getCurrUserId(request);
		boolean zt = false;
		
		UserMotionLike userMotionLike = new UserMotionLike();
		userMotionLike.setCreateDate(createDate);
		userMotionLike.setCreateTime(System.currentTimeMillis());
		userMotionLike.setUserid(userId);
		userMotionLike.setZuserid(rid);
			
		zt = userMotionLikeService.save(userMotionLike)!=null;
		
		if(zt){
			return ResultJsonBuild.buildObj(ResultCode.SUCCESS);
		}else{
			return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);	
		}
	}
	@ApiOperation(value = "运动取消点赞", notes = "运动取消点赞")
	@ApiImplicitParams({ @ApiImplicitParam(name = "rid", required = true, value = "对方ID", dataType="String", paramType = "query"),
		@ApiImplicitParam(name = "createDate", required = true, value = "时间戳(精确到毫秒)", dataType="String", paramType = "query") })
	@PostMapping(value = "/delmotionLike")
	@ResponseBody
	public ResultJson<Object> delmotionLike(HttpServletRequest request, @RequestParam(required = true)Long rid, @RequestParam(required = true)Long createDate) {
		Long userId = SiteUtil.getCurrUserId(request);
		
		UserMotionLikeKey idKey = new UserMotionLikeKey(userId, rid, createDate);
		Optional<UserMotionLike> optional = userMotionLikeService.findById(idKey);
		if(optional.isPresent()) {
			UserMotionLike userMotionLike = new UserMotionLike();
			userMotionLike.setCreateDate(getDateTime(createDate));
			userMotionLike.setCreateTime(createDate);
			userMotionLike.setUserid(userId);
			userMotionLike.setZuserid(rid);
			
			userMotionLikeService.delete(userMotionLike);
			return ResultJsonBuild.buildObj(ResultCode.SUCCESS);
		}else {
			return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);
		}
	}
	
	
	
	@ApiOperation(value = "获取运动背景图片", notes = "获取运动背景图片")
	@PostMapping(value = "/getUserUrl")
	@ResponseBody
	public ResultJson<Object> getUserUrl(HttpServletRequest request, @RequestParam(required = true)Long rid) {
		ResultJsonBuild<Object> resultJson = new ResultJsonBuild<Object>();
		Optional<UserImage> optional = userImageService.findById(String.valueOf(rid));
		if(optional.isPresent()) {
			UserImage userImage = optional.get();
			return resultJson.success(userImage);
		}else {
			return resultJson.success();
		}
	}
	@ApiOperation(value = "修改运动背景图片", notes = "修改运动背景图片")
	@ApiImplicitParams({ @ApiImplicitParam(name = "url", required = true, value = "需要修改的地址", dataType="String", paramType = "query")})
	@PostMapping(value = "/setUserUrl")
	@ResponseBody
	public ResultJson<Object> setUserUrl(HttpServletRequest request, @RequestParam(required = true)String url) {
		Long userId = SiteUtil.getCurrUserId(request);
		Optional<UserImage> optional = userImageService.findById(String.valueOf(userId));
		boolean zt = false;
		if(optional.isPresent()) {
			UserImage userImage = optional.get();
			userImage.setUser_uri(url);
			zt = userImageService.save(userImage)!=null;
		}else {
			UserImage image = new UserImage();
			image.setUser_id(String.valueOf(userId));
			image.setUser_uri(url);
			zt = userImageService.save(image)!=null;
		}
		if(zt) {
			return ResultJsonBuild.buildObj(ResultCode.SUCCESS);
		}
		return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);
	}
	@ApiOperation(value = "获取点赞列表", notes = "获取点赞列表")
	@ApiImplicitParams({ @ApiImplicitParam(name = "userid", required = true, value = "用户id", dataType="String", paramType = "query"),
			@ApiImplicitParam(name = "createDate", required = true, value = "时间戳", dataType="String", paramType = "query")})
	@PostMapping(value = "/getLikeList")
	@ResponseBody
	public ResultJson<List<Map<String, Object>>> getLikeList(HttpServletRequest request, @RequestParam(required = true)Long userid, @RequestParam(required = true)Long createDate) {
	//	Long userId = SiteUtil.getCurrUserId(request);
		ResultJson<List<Map<String, Object>>> resultJson = new ResultJson<List<Map<String, Object>>>();
		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		
		List<UserMotionLike> getMotionLikeZuserid = userMotionLikeService.findByUseridAndCreateDate(userid,createDate);
		StringBuffer stringBuffer = new StringBuffer();
		String ids = null;
		if(getMotionLikeZuserid!=null&&getMotionLikeZuserid.size()>0) {
			for (UserMotionLike userMotionLike : getMotionLikeZuserid) {
				stringBuffer.append(userMotionLike.getUserid()+",");
			}
			ids = stringBuffer.toString().substring(0,stringBuffer.length()-1);
		}else {
			List<Map<String, Object>> resultList1 = null;
			return resultJson.setObj(resultList1);
		}
		
		List<Map<String,Object>> findByUserid = userService.selectByUserid(ids);
		
		for (Map<String, Object> map : findByUserid) {
			Map<String, Object> map2 = new HashMap<String,Object>();
			Long rid= Long.valueOf(map.get("userid").toString());
			String image = map.get("image").toString();
			String nickName = map.get("nickName").toString();
			map2.put("userid", rid);
			map2.put("image", image);
			map2.put("nickName", nickName);
			map2.put("createDate", createDate);
			resultList.add(map2);
		}
		return resultJson.setObj(resultList);
	}
	
	
	
	@ApiOperation(value = "获取用户运动步数", notes = "获取用户运动步数")
	@ApiImplicitParams({ @ApiImplicitParam(name = "userid", required = true, value = "用户id", dataType="String", paramType = "query"),
			@ApiImplicitParam(name = "date", required = true, value = "展示天数", dataType="int",example="0", paramType = "query")})
	@PostMapping(value = "/getUserStepNum")
	@ResponseBody
	public ResultJson<Object> getUserStepNum(HttpServletRequest request, @RequestParam(required = true)int userid, @RequestParam(required = true)long date) {
		if(!(date >= 10 && date <=30)){
			date = 10;
		}
		ResultJson<Object> resultJson = new ResultJson<Object>();
		
		long createDate=System.currentTimeMillis();
		long nowtime = 1000*60*60*24*date;
		createDate = createDate-nowtime;
		long startTime = getDateTime(createDate);
		
		List<Map<String, Object>> list = userMotionService.getUserStepNum(userid, startTime);
		
		long endTime = getDateTime();
		int day=(int) ((endTime-startTime)/(1000*60*60*24));
		
		//获取数据库的天数
		logger.info("day:"+day);
		List<Long> listDay=new ArrayList<>();
		for (int i=0;i<day;i++) {
			if(i != 0){
				listDay.add(startTime);
			}
			startTime += 1000*60*60*24;
		}
		logger.info("dayList:"+listDay);
		
		if(listDay.size()<10){
			listDay.add(endTime);
		}
		
		//获取数据库的天数
		List<Long> dbListDay=new ArrayList<>();
		for (Map<String, Object> map : list) {
			long dbCreateDate = Long.valueOf(map.get("createDate").toString()).longValue();
			dbListDay.add(dbCreateDate);
		}
		
		for (Long lday : listDay) {
			if(!dbListDay.contains(lday)){
				Map<String, Object> bmap = new HashMap<String, Object>();
				bmap.put("createdate", lday);
				bmap.put("stepnum", 0);
				list.add(bmap);
			}
		}
		if(list!=null&&list.size()>0){
			Collections.sort(list, new Comparator<Map<String, Object>>() {
				
				@Override
				public int compare(Map<String, Object> o1,
						Map<String, Object> o2) {
					long o1Day= Long.valueOf(o1.get("createdate").toString());
					long o2Day= Long.valueOf(o2.get("createdate").toString());
					if(o1Day > o2Day){
						return 1;
					}else if(o1Day < o2Day){
						return -1;	
					}else{
						return 0;								
					}
				}
				
			});
		//	String json=JSONArray.fromObject(list).toString();
			
		
			return resultJson.setObj(list);
		}
		return resultJson.setCode(ResultCode.UNKONW_ERROR.getCode());
	
	}
	
	@ApiOperation(value = "添加黑名单", notes = "添加黑名单")
	@ApiImplicitParams({ @ApiImplicitParam(name = "rid", required = true, value = "对方ID", dataType="String", paramType = "query")})
	@PostMapping(value = "/insertShieldedList")
	@ResponseBody
	public ResultJson<Object> insertShieldedList(HttpServletRequest request, @RequestParam(required = true)String rid) {
		Long userId = SiteUtil.getCurrUserId(request);

		
		UserBlackKey userBlackKey = new UserBlackKey(userId.longValue(), rid);
		Optional<UserBlack> findById = userBlackService.findById(userBlackKey);
		if(findById.isPresent()) {
			return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);
		}
		
		boolean b = false;
		UserBlack userBlack = new UserBlack();
		userBlack.setUserid(userId.longValue());
		userBlack.setRid(rid);
		userBlack.setUpdateTime(new Date());
		b = userBlackService.save(userBlack)!=null;
		
		
		if(b) {
			return ResultJsonBuild.buildObj(ResultCode.SUCCESS);
		}else {
			return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);
		}
		
	}
	@ApiOperation(value = "查询黑名单", notes = "查询黑名单")
	@PostMapping(value = "/selectShieldedList")
	@ResponseBody
	public ResultJson<List<UserBlack>> selectShieldedList(HttpServletRequest request) {
		Long userId = SiteUtil.getCurrUserId(request);
		
		ResultJson<List<UserBlack>> resultJson = new ResultJson<List<UserBlack>>();
		
		List<UserBlack> list = userBlackService.findByUserid(userId.longValue());
		if(list!=null&&list.size()>0) {
			return resultJson.setObj(list);
		}
		return resultJson;
	}
	@ApiOperation(value = "删除黑名单", notes = "删除黑名单")
	@ApiImplicitParams({ @ApiImplicitParam(name = "rid", required = true, value = "对方ID", dataType="String", paramType = "query")})
	@PostMapping(value = "/delShieldedList")
	@ResponseBody
	public ResultJson<Object> delShieldedList(HttpServletRequest request, @RequestParam(required = true)String rid) {
		Long userId = SiteUtil.getCurrUserId(request);
		
		UserBlackKey userBlackKey = new UserBlackKey(userId.longValue(), rid);
		Optional<UserBlack> findById = userBlackService.findById(userBlackKey);
		if(!findById.isPresent()) {
			return ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);
		}
		
		UserBlack userBlack = findById.get();
		userBlackService.delete(userBlack);
		
		return ResultJsonBuild.buildObj(ResultCode.SUCCESS);
		
	}
	@ApiOperation(value = "根据手机号获取联系人信息", notes = "根据手机号获取联系人信息")
	@ApiImplicitParams({ @ApiImplicitParam(name = "phones", required = true, value = "对方ID", dataType="String", paramType = "query")})
	@PostMapping(value = "/getInfoByPhone")
	@ResponseBody
	public ResultJson<List<Map<String, Object>>> getInfoByPhone(HttpServletRequest request, @RequestParam(required = true)String phones) {
		ResultJson<List<Map<String, Object>>> resultJson = new ResultJson<List<Map<String, Object>>>();
		Long userId = SiteUtil.getCurrUserId(request);
		List<Integer> rosterId = goodfirendService.selectRoster1(userId);
		
		List<Map<String, Object>> infoByPhone = userService.getInfoByPhone(phones);
		
		for (Map<String, Object> map : infoByPhone) {
			int parseInt = Integer.parseInt(map.get("userid").toString());
			if(rosterId.contains(parseInt)) {
				Goodfirend goodfirend = goodfirendService.findByUseridAndJid(userId, Long.valueOf(parseInt));
				if(goodfirend!=null) {
					map.put("relation", goodfirend.getRelation());
				}else {
					map.put("relation", -2);
				}
			}else {
				map.put("relation", -2);
			}
		}
		
    	return resultJson.setObj(infoByPhone);
		
	}
	@ApiOperation(value = "获取随机十个联系人", notes = "获取随机十个联系人")
	@PostMapping(value = "/recommendedFriends")
	@ResponseBody
	public ResultJson<Object> recommendedFriends(HttpServletRequest request) {
		ResultJson<Object> resultJson = new ResultJson<Object>();
		Long userId = SiteUtil.getCurrUserId(request);
		List<Integer> rosterId = goodfirendService.selectRoster(userId);
		
		int gender = userService.selectGenderByUsreId(userId);
		
		List<Map<String, Object>> randomUserInfo = userService.randomUserInfo(rosterId, gender);
		
		
		if(randomUserInfo!=null&&randomUserInfo.size()>0){
			return resultJson.setObj(randomUserInfo);
    	}
		return resultJson.setCode(ResultCode.UNKONW_ERROR.getCode());
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	private long getDateTime(){
		Date date=new Date();
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date);
		cal1.set(Calendar.HOUR_OF_DAY, 0);
		cal1.set(Calendar.MINUTE, 0);
		cal1.set(Calendar.SECOND, 0);
		cal1.set(Calendar.MILLISECOND, 0);
		return cal1.getTimeInMillis();
	}
	
	
	private long getDateTime(Long createDate){
		Date date=new Date(createDate);
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date);
		cal1.set(Calendar.HOUR_OF_DAY, 0);
		cal1.set(Calendar.MINUTE, 0);
		cal1.set(Calendar.SECOND, 0);
		cal1.set(Calendar.MILLISECOND, 0);
		return cal1.getTimeInMillis();
	}
	
	
	
	
	
	
	
	
}
